package com.gz.view;

import com.gz.service.MangeClientConnectServerThread;
import com.gz.service.MessageClientService;
import com.gz.service.SendFileServer;
import com.gz.service.UserClientService;
import com.gz.utilis.Utility;



public class QQview {
    public static void main(String[] args) {
        new QQview().mainmenu();
        System.out.println("客户端退出系统...");
    }
    private boolean loop=true;
    private String key="";
    private UserClientService userClientService=new UserClientService();
    private MessageClientService messageClientService=new MessageClientService();//用于私聊、群聊
    private SendFileServer sendFileServer=new SendFileServer();
    String receiver="";
    public void mainmenu(){
        while(loop){
            System.out.println("==============欢迎登录网络通信系统==============");
            System.out.println("\t\t 1 登录系统");
            System.out.println("\t\t 9 退出系统");

            key= Utility.readString(1);

            switch(key){
                case "1":
                    System.out.print("请输入用户号: ");
                    String userId= Utility.readString(50);
                    System.out.print("请输入密 码: ");
                    String password= Utility.readString(50);
                    if(userClientService.checkUser(userId,password)){
                        System.out.println("==============欢迎用户 "+userId+" 登录成功 ==============");
                        while(loop){
                            try {
                                Thread.sleep(500);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                            System.out.println("\n==============网络通信系统二级菜单(用户 "+userId+" )==============");
                            System.out.println("\t\t1 显示在线用户列表");
                            System.out.println("\t\t2 群发消息");
                            System.out.println("\t\t3 私聊消息");
                            System.out.println("\t\t4 发送文件");
                            System.out.println("\t\t9 退出系统");
                            System.out.println("请输入你的选择: ");
                            key= Utility.readString(1);
                            switch(key){
                                case "1":
                                    userClientService.onlineUserList();
                                    break;
                                case "2":
                                    System.out.print("请输入你要发送的内容: ");
                                    String content_to_all=Utility.readString(100);
                                    messageClientService.sendMessagetoAll(content_to_all,userId);
                                    break;
                                case "3":
                                    System.out.print("请输入你要发送的用户: ");
                                    receiver=Utility.readString(50);
                                    System.out.print("请输入你要发送的内容: ");
                                    String content=Utility.readString(100);
                                    messageClientService.sendMessagetoOne(content,userId,receiver);
                                    break;
                                case "4":
                                    System.out.print("请输入你要发送的用户: ");
                                    receiver=Utility.readString(50);
                                    System.out.println("请输入发送的文件的完整路径(形式e:\\xxx.jpg)");
                                    String senderfilepath=Utility.readString(100);
                                    System.out.println("请输入发送文件到对方的完整路径(形式e:(形式e:\\xxx.jpg)");
                                    String receiverfilepath=Utility.readString(100);
                                    sendFileServer.sendMessagetoOne_file(
                                            senderfilepath,receiverfilepath,userId,receiver);

                                    break;
                                case "9":
                                    userClientService.logout();
                                    loop=false;
                                    break;
                            }
                        }
                    }
                    else{
                        System.out.println("=======登陆系统失败========\n");
                    }
                    break;
                case "9":
                    loop=false;
                    break;
            }
        }
    }
}
